#ifndef _FONTLIB_H
#define _FONTLIB_H

#include "header.h"

#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

class Char {
public:
    static const int s_CHAR_SIZE = 64;

    ushort getValue() {
        return m_value;
    }
    void setValue(ushort value) {
        m_value = value;
    }

    uchar * getImageData() {
        return m_imageData;
    }
    void assignImageData(uchar *imageData) {
        memcpy(m_imageData, imageData, s_CHAR_SIZE * s_CHAR_SIZE * sizeof(uchar));
    }

    void storeData(FILE* file);

    static Char *parseLibFile(FILE *file);

    Char() {
        m_value = 0;
        m_imageData = new uchar[s_CHAR_SIZE * s_CHAR_SIZE];
    }

    Char(const Char &copy) {
        m_value = copy.m_value;

        m_imageData = new uchar[s_CHAR_SIZE * s_CHAR_SIZE];
        memcpy(m_imageData, copy.m_imageData, s_CHAR_SIZE * s_CHAR_SIZE * sizeof(uchar));
    }

    virtual ~Char() {
        delete[] m_imageData;
    }

protected:
    /** the unicode value of this item */
    ushort m_value;

    /** the binary grey data of this item */
    uchar *m_imageData;
};

class FontLib {
public:
    Char * at(int index) {
        return m_charArray.at(index);
    }
    void push_back(Char *c) {
        m_charArray.push_back(c);
    }
    int size() {
        return m_charArray.size();
    }

    static void genCurrFontLib();

    static FontLib *parseLibFile(FILE *file);
    
    void storeData(FILE *file);

    virtual ~FontLib();

private:
    /** wide font data: font data of multibytes chars */
    vector<Char *> m_charArray;

    static void buildSubset(FILE *file, FILE *cfile, ushort *subset, int len);

    FontLib() {
    }
};

#endif
